from manim import *



class math4(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
        text0 = Tex(r"$y'+p\left( x\right) y=0$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,20,0])
        text00 = Tex(r"$\Rightarrow $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,20,0])
        text000 = Tex(r"$y=c\cdot e^{-\int p\left( x\right) dx} $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,20,0])
        text1 = Tex(r"$y'+p\left( x\right) y=q\left( x\right)$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,12,0])
        text10 = Tex(r"$\Rightarrow$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,12,0])
        text100 = Tex(r"$y=e^{-\int p\left( x\right) dx}\cdot \left( \int q\left( x\right) e^{\int p\left( x\right) dx}dx+c\right) $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,12,0])
        text2 = Tex(r"$y'+p\left( x\right) y=q\left( x\right) y^{n}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,4,0])
        text20 = Tex(r"$\Rightarrow$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,4,0])
        text200 = Tex(r"\text{令}$z=y^{1-n}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,4,0])
        
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=28,height=23
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-30,12,0])
        

        arrow = Arrow(start=[-30,-1,0],end=[-30,-12,0],color=RED
                       , stroke_width=20, tip_length=1)

        


        text3 = Tex(r"\text{孤立}$y'$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,-15,0])
        text30 = Tex(r"\text{(判齐次)}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text3,DOWN,buff=1)
        arrow1 = Arrow(start=[-20,-15,0],end=[-10,-15,0],color=RED
                       , stroke_width=20, tip_length=1)

   
        text4 = Tex(r"\text{还原}$y'=\dfrac{dy}{dx}$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-15,0])
        text40 = Tex(r"\text{(判分离)}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text4,DOWN,buff=1)
        
        arrow2 = Arrow(start=[10,-15,0],end=[20,-15,0],color=RED
                       , stroke_width=20, tip_length=1)


        text5 = Tex(r"\text{非特定类型}",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([30,-15,0])
        
        
        
        #下划线
        #下划线
        dot4=Dot([0,15,0])
        dot5=Dot([0,-20,0])
        line=Line(dot4,dot5).set_color(PURPLE)
        line.set_stroke(width=30)  # 设置宽度为 30
        #self.play(Create(line))
        text6 = Tex(r"$\Rightarrow z=-\dfrac{1}{3}+c\cdot e^{-\dfrac{3}{2}x^{2}}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,12,0])
        text7 = Tex(r"$\Rightarrow \dfrac{1}{y}=-\dfrac{1}{3}+c\cdot e^{-\dfrac{3}{2}x^{2}}$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,4,0])
        text8 = Tex(r"$\Rightarrow \dfrac{u-2}{ux^{2}}=\pm e^{c}=c'$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-4,0])
        text9 = Tex(r"$y\left( 1\right) =1\Rightarrow u=1\Rightarrow c'=-1$",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-12,0])
        text11 = Tex(r"$\Rightarrow y=\dfrac{2x}{1+x^{2}}$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-20,0])





        
        self.play(Create(text0),Create(text00),Create(text000),Create(text1),Create(text10),Create(text100),Create(text2),Create(text20),Create(text200))
        self.play(Create(rectangle))
        self.play(Create(arrow))
        self.play(Create(text3),Create(text30))
        self.play(Create(arrow1))
        self.play(Create(text4),Create(text40))
        self.play(Create(arrow2),Create(text5))
        #镜头拉回
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        #题目向上移动
       
        self.wait()